import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class text {
    public static void main(String[] args) throws SQLException {
        DataSource datasource=new MysqlDataSource();
        ((MysqlDataSource)datasource).setURL("jdbc:mysql://127.0.0.1:3306/java_114?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)datasource).setUser("root");
        ((MysqlDataSource)datasource).setPassword("1291691906");
        Connection connection=datasource.getConnection();
        Scanner b=new Scanner(System.in);
       System.out.println("请输入id");
        int id=b.nextInt();
        System.out.println("请输入name");
      String name=b.next();

        //String sql="insert into student values(?,?)";
        //String sql="delete from student where id=? or name=?";
        String sql="update student set id=? where name=?";
      // Scanner scanner=new Scanner(System.in);
        //int id=scanner.nextInt();
        //String name=scanner.nextLine();

        PreparedStatement preparedStatement= connection.prepareStatement(sql);
        preparedStatement.setInt(1,id);
       preparedStatement.setString(2,name);


        int ret=preparedStatement.executeUpdate();
        System.out.println("ret="+ret);
        //System.out.println("sql:"+preparedStatement);
        //ResultSet resultset=preparedStatement.executeQuery();
        /*while(resultset.next())
        {
            int id=resultset.getInt("id");
            String name=resultset.getString("name");
            System.out.println("id="+id+" "+"name="+name);
        }

         */
        //resultset.close();


        preparedStatement.close();
        connection.close();




    }



        // write code here


}
